package com.gmall.common.config;


import com.gmall.common.constants.MqConst;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class GoodsRabbitMQConfig {

    @Bean(MqConst.EXCHANGE_DIRECT_GOODS)
    public Exchange EXCHANGE_DIRECT_GOODS(){
        return ExchangeBuilder
                .directExchange(MqConst.EXCHANGE_DIRECT_GOODS)
                .durable(true)//交换机持久化
                .build();
    }

    @Bean(MqConst.QUEUE_GOODS_UPPER)
    public Queue QUEUE_GOODS_UPPER(){
        return QueueBuilder
                .durable(MqConst.QUEUE_GOODS_UPPER)
                .build();
    }

    @Bean(MqConst.QUEUE_GOODS_LOWER)
    public Queue QUEUE_GOODS_LOWER(){
        return QueueBuilder.durable(MqConst.QUEUE_GOODS_LOWER).build();
    }


    @Bean
    public Binding binding_direct_1(
            @Qualifier(MqConst.QUEUE_GOODS_UPPER) Queue queue,
            @Qualifier(MqConst.EXCHANGE_DIRECT_GOODS) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with(MqConst.ROUTING_GOODS_UPPER).noargs();
    }

    @Bean
    public Binding binding_direct_2(
            @Qualifier(MqConst.QUEUE_GOODS_LOWER) Queue queue,
            @Qualifier(MqConst.EXCHANGE_DIRECT_GOODS) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with(MqConst.ROUTING_GOODS_LOWER).noargs();
    }
}
